package com.songlanyun.modules.rabbitmq.publicbenefitmsg.impl;

import com.songlanyun.common.enums.DonationConstant;
import com.songlanyun.common.enums.PrivateMessageConstant;
import com.songlanyun.modules.message.model.to.MessageTO;
import com.songlanyun.modules.publicbenefitmsg.entity.PublicBenefitMsgEntity;
import com.songlanyun.modules.publicbenefitmsg.model.to.PublicBenefitMsgTO;
import com.songlanyun.modules.publicbenefitmsg.service.PublicBenefitMsgService;
import com.songlanyun.modules.rabbitmq.interactmsg.IInteractMsgService;
import com.songlanyun.modules.rabbitmq.publicbenefitmsg.IPublicBenefitMsgService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@Service("iPublicBenefitMsgService")
public class PublicBenefitMsgServiceImpl implements IPublicBenefitMsgService {

    private Map<Integer, IPublicBenefitMsgService> iServices = new HashMap<>();

    public PublicBenefitMsgServiceImpl(IPublicBenefitMsgService donateMsgService,
                                       IPublicBenefitMsgService buyMsgService
    ) {
        //消息
        iServices.put(DonationConstant.MsgType.DONATE.getCode(), donateMsgService);
        iServices.put(DonationConstant.MsgType.BUY.getCode(), buyMsgService);

    }

    @Override
    public void saveMsg(PublicBenefitMsgTO to) {
        Integer type = to.getType().getCode();
        if (iServices.containsKey(type)) {
            iServices.get(type).saveMsg(to);
        }

    }
}
